<template>
  <div class="stickHeader" :class="{ show: top > 80 }">
    <div class="container" v-show="top > 80">
      <div class="one"></div>
      <div class="two">
        <common-header ></common-header>
      </div>
      <div class="three">
        <router-link to="/">品牌</router-link>
        <router-link to="/">专题</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import CommonHeader from "./CommonHeader.vue";
//引入自己写的防抖函数
import { throttle } from "@/utils/constfun";
//引入插件的防抖函数
import _ from "lodash";
export default {
  components: { CommonHeader },
  data() {
    return {
      top: 0, //记录滑下来的高度
    };
  },
  mounted() {
    //在mouted中操作dom元素 滚动高度大于80时候做逻辑处理
    //监听滚动条高度，滚动条高度大于80做逻辑处理
    // window.addEventListener("scroll", this.setTop);
    //添加防抖函数  传统节流实现
    // window.addEventListener("scroll", throttle(this.setTop));
    //防抖函数插件
    window.addEventListener("scroll", _.throttle(this.setTop, 200));
  },
  methods: {
    setTop() {
      this.top = document.documentElement.scrollTop;
      // console.log(this.top);
    },
  },
  //事件关闭
  beforeDestroy() {
    window.removeEventListener("scroll", throttle(this.setTop));
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/css/color.scss";
.stickHeader {
  z-index: 999;
  width: 100%;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  position: fixed;
  top: 0;
  min-width: 1800px;
  border-bottom: 1px solid #eee;
  .container {
    height: 80px;
    display: flex;
    align-items: center;
    .one {
      width: 200px;
      height: 100%;
      background-image: url("@/assets/img/logo.tu.png");
      background-repeat: no-repeat;
      background-position: center;
      background-size: 100%;
    }
    .two {
      width: 820px;
      height: 100%;
    }
    .three {
      display: flex;
      justify-content: space-around;
      align-content: center;
      width: 220px;
      height: 16px;
      padding-left: 40px;
      border-left: 2px solid #27ba9b;
      a {
        font-size: 16px;
        width: 40px;
        height: 16px;
        line-height: 1;
      }
      a:hover {
        color: $sucColor;
      }
    }
  }
  transform: translateY(-100%);
  opacity: 0;
  &.show {
      // transform: translateY(-100%);
    transition: all 0.3s linear;
    transform: none;
    opacity: 1;
  }
}
</style>